﻿using System;
using System.Collections.ObjectModel;
using System.Windows.Input;

namespace ColinHan.Windows.Foundation.MVVM
{
    /// <summary>
    /// Represents an actionable item displayed by a View.
    /// </summary>
    public class CommandViewModel : ViewModelBase
    {
        public CommandViewModel(string displayName, ICommand command)
            : this(displayName, command, null)
        { }
        public CommandViewModel(string displayName, ICommand command, object commandParameter)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            base.DisplayName = displayName;
            this.Command = command;
            this.CommandParameter = commandParameter;
        }

        private ICommand _command;
        public ICommand Command
        {
            get { return _command; }
            set
            {
                if (this._command != value)
                {
                    this._command = value;
                    this.OnPropertyChanged("Command");
                }
            }
        }
        private object _commandParameter;
        public object CommandParameter
        {
            get { return this._commandParameter; }
            set
            {
                if (this._commandParameter != value)
                {
                    this._commandParameter = value;
                    this.OnPropertyChanged("CommandParameter");
                }
            }
        }
    }

    public class CommandViewModelCollection : ObservableCollection<CommandViewModel>
    {
    }

    public class Group : Collection<object>
    {
        public Group(string name, params object[] items)
            : base(items)
        {
            this.Name = name;
        }
        public string Name { get; set; }
        public override string ToString()
        {
            return this.Name;
        }
    }
}